package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 会话配置数据类型枚举
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-12
 */
public enum SessionValueType implements BaseEnum {
    STRING("STRING", "字符串"),
    INTEGER("INTEGER", "整数"),
    DOUBLE("DOUBLE", "浮点数"),
    BOOLEAN("BOOLEAN", "布尔值"),
    JSON("JSON", "JSON对象"),
    ARRAY("ARRAY", "数组"),
    DATETIME("DATETIME", "日期时间"),
    FILE_PATH("FILE_PATH", "文件路径");

    private final String code;
    private final String description;

    SessionValueType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据代码查找枚举值
     *
     * @param code 枚举代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static SessionValueType fromCode(String code) {
        for (SessionValueType type : SessionValueType.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown session value type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 枚举描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static SessionValueType fromDescription(String description) {
        for (SessionValueType type : SessionValueType.values()) {
            if (type.description.equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown session value type description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}